<%@ page import="org.gnomus.server.Context" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%
  Context ctx = Context.get();
  Map klass = (Map) ctx.data.get("class");
  if (klass != null) {
    List<Map> user_list = (List<Map>) ctx.data.get("user_list");
    List<Map> lesson_list = (List<Map>) ctx.data.get("lesson_list");
    List<Map> students = (List<Map>) klass.get("students");
    List<Map> assignments = (List<Map>) klass.get("assignments");
%>
<a class="f-right" href="/teach">
  Return to class list
</a>
<h3><%= klass.get("title") %></h3>
<div id="assignments" class="f-left" style="width:48%;">
  <a class="f-right" onclick="$('#create_assignment').show();">
    Create assignment
  </a>
  Assignments
  <div class="border-1" style="padding:8px; min-height:128px;">
    <%
      if (assignments != null) {
        for (Map assignment : assignments) {
    %>
    <div>
      <%= assignment.get("title") %>
    </div>
    <%
        }
      } else {
    %>
    This class has no assignments.
    <%
      }
    %>
  </div>
</div>
<div id="students" class="f-right" style="width:48%;">
  <a class="f-right" onclick="$('#add_student').show();">
    Add student
  </a>
  Students
  <div class="border-1" style="padding:8px; min-height:128px;">
    <%
      if (students != null) {
        for (Map student : students) {
    %>
    <div>
      <%= student.get("full_name") %>
    </div>
    <%
        }
      } else {
    %>
    This class has no students.
    <%
      }
    %>
  </div>
</div>
<div id="create_assignment" class="d-none popup" style="left:32px;top:32px;">
  <div class="popup-close"><a onclick="$('#create_assignment').hide()">&#215;</a></div>
  <h3>Create assignment</h3>
  <hr />
  <form action="/teach/create_assignment" method="POST">
    <table>
      <tr>
        <td>
          <label for="lesson_id">
            Lesson :
          </label>
        </td>
        <td>
          <select name="lesson_id">
            <%
              if (lesson_list != null) {
                for (Map lesson : lesson_list) {
            %>
            <option value="<%= lesson.get("id") %>">
              <%= lesson.get("title") %>
            </option>
            <%
                }
              }
            %>
          </select>
        </td>
        <td>
          <input type="submit" value="Create assignment" />
        </td>
      </tr>
    </table>
    <input type="hidden" name="id" value="<%= klass.get("id") %>" />
  </form>
</div>
<div id="add_student" class="d-none popup" style="right:32px;top:32px;">
  <div class="popup-close"><a onclick="$('#add_student').hide()">&#215;</a></div>
  <h3>Add student</h3>
  <hr />
  <form action="/teach/add_student" method="POST">
    <table>
      <tr>
        <td>
          <label for="user_id">
            Student name :
          </label>
        </td>
        <td>
          <select name="user_id">
            <%
              if (user_list != null) {
                for (Map user : user_list) {
            %>
            <option value="<%= user.get("id") %>">
              <%= user.get("full_name") %>
            </option>
            <%
                }
              }
            %>
          </select>
        </td>
        <td>
          <input type="submit" value="Add student" />
        </td>
      </tr>
    </table>
    <input type="hidden" name="id" value="<%= klass.get("id") %>" />
  </form>
</div>
<div class="clear"></div>
<%
  } else if (ctx.errors.size() > 0) {
    for (Object error : ctx.errors) {
      if (error instanceof String) {
%>
<%= error %>
<%
      }
    }
  } else {
%>
Unknown error.
<%
  }
%>